﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CGOnline.Server.Core;

namespace CGOnline.Server.UserLayer
{

    [StateAnnouncement(StateGroup = ROOM_STATEGROUP, StateName = ROOM_STATEGROUP_OPEN)]
    [StateAnnouncement(StateGroup = ROOM_STATEGROUP, StateName = ROOM_STATEGROUP_CLOSE)]
    [StateAnnouncement(StateGroup = ROOM_STATEGROUP, StateName = ROOM_STATEGROUP_GAMERUN)]
    abstract public class RoomBase : StateObject
    {
        public const string ROOM_STATEGROUP = "RoomState";
        public const string ROOM_STATEGROUP_OPEN = "Open";
        public const string ROOM_STATEGROUP_CLOSE = "Close";
        public const string ROOM_STATEGROUP_GAMERUN = "GameRun";

        public event RoomBroadcastHandler Broadcast;
        protected void onBroadcast(object sender,RoomEventType eventtype,object data)
        {
            if (Broadcast != null)
                Broadcast(
                    sender,
                    new RoomEventArgs { EventData = data, EventType = eventtype}
                    );
        }

        abstract internal bool UserIn(UserBase user, object data);
        abstract internal bool UserLeave(UserBase user);
        abstract internal bool UserSendMsg(UserBase user, Message msg);
        abstract internal List<Message> UserGetMsgs(UserBase user, DateTime time);
        abstract public List<UserConfig> ListUser();
        abstract public void GameStart();

        public RoomConfig Config { get; protected set; }

    }

    public enum RoomEventType
    {
        NewMsg,
        GameStart,
        UserIn,
        UserLeave,
        ControlGrant
    }
    public class RoomEventArgs : MyEventArgs
    {
        public RoomEventType EventType { get; set; }
        public object EventData { get; set; }
    }
    public delegate void RoomBroadcastHandler(object sender,RoomEventArgs e);
}
